package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description NursingPlanServicelmpl
 * @Author pengtao
 * @Date 2025-05-11  15:45
 */
@Service
public class NursingPlanServicelmpl implements NursingPlanService {
    @Autowired
    private NursingPlanMapper nursingPlanMapper;

    // 新增
    @Override
    public void save(NursingPlanVo nursingPlanVo) {
        nursingPlanVo.setCreateTime(LocalDateTime.now());
        nursingPlanVo.setUpdateTime(LocalDateTime.now());
        nursingPlanMapper.insert(nursingPlanVo);

        Long id = nursingPlanVo.getId();
        List<NursingPlanVo> nursingPlanVos = nursingPlanMapper.getNursingPlanVo();

    }

    // 查询
    @Override
    public NursingPlanDto getById(Long id) {
        NursingPlan nursingPlan = nursingPlanMapper.selectByPrimaryKey(id);
        return BeanUtil.toBean(nursingPlan, NursingPlanDto.class);
    }

    // 删除
    @Override
    public void delete(Long id) {
        nursingPlanMapper.delete(id);
    }

    // 修改
    @Override
    public void update(NursingPlanDto nursingPlanDto) {


    }

    // 分页查询
    @Override
    public PageResponse<NursingPlanDto> search(String planName, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingPlan> nursingPlans = nursingPlanMapper.selectByPage(planName, status);
        PageResponse<NursingPlanDto> nursingPlanDtoPageResponse = PageResponse.of(nursingPlans, NursingPlanDto.class);
        return nursingPlanDtoPageResponse;
    }
    // 获取所有
    @Override
    public List<NursingPlanVo> getAll() {
        return nursingPlanMapper.getNursingPlanVo();
    }
}
